const suffix = "_expire";
class LocalStorage {
    setItem(key, value, expire) {
        if (!key) {
            throw new Error(`key is invalid`)
        }
        if (expire && isNaN(expire)) {
            throw new Error(`${expire} is invalid expire time`)
        }
        tt.setStorageSync(key, value);
        expire && tt.setStorageSync(key + suffix, new Date().getTime() + expire);
    }
    getItem(key) {
        if (!key) {
            throw new Error(`key is invalid`)
        }
        const res = tt.getStorageSync(key);
        const expire = tt.getStorageSync(key + suffix);
        if (expire && expire < new Date().getTime()) {
            tt.removeStorageSync(key);
            tt.removeStorageSync(key + suffix);
            return null

        }
        return res;
    }
    clear(key) {
        if (!key) {
            throw new Error(`key is invalid`)
        }
        tt.clearStorageSync(key);
    }
}
module.exports = new LocalStorage();